#!/usr/bin/python
# -*- coding: utf-8 -*-
import file_handle
import html_data
from bs4 import BeautifulSoup
import chardet


class Novel:
	def __init__(self, name, index_page, chapters, local_path):
		self.name = name
		self.index_page = index_page
		self.chapters = chapters
		self.local_path = local_path

	def start(self):
		file_handle.file_write_w(self.local_path, self.name)
		for i in self.chapters:
			file_handle.file_write_a(self.local_path, i.getname())
			html_context = html_data.get_html(i.geturl())
			soup = BeautifulSoup(html_context, 'html.parser')
			divs = soup.find_all('div', id='content')
			context = divs[0].contents[1].string
			file_handle.file_write_a(self.local_path, context.encode('utf-8'))


class Novel_chapter:
	def __init__(self, url, name):
		self.url = url
		self.name = name

	def out(self):
		print(str(self.url) + '|' + self.name)

	def geturl(self):
		return self.url

	def getname(self):
		return self.name
